package com.lavida.project.system.review.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lavida.common.utils.security.ShiroUtils;
import com.lavida.framework.aspectj.lang.annotation.Log;
import com.lavida.framework.aspectj.lang.enums.BusinessType;
import com.lavida.framework.web.controller.BaseController;
import com.lavida.framework.web.page.TableDataInfo;
import com.lavida.project.system.dept.domain.Dept;
import com.lavida.project.system.dept.service.DeptServiceImpl;
import com.lavida.project.system.dept.service.IDeptService;
import com.lavida.project.system.emp.service.RosterService;
import com.lavida.project.system.review.domain.Penalty;
import com.lavida.project.system.review.service.PenaltyService;
import com.lavida.project.system.user.domain.User;
import com.lavida.project.system.user.service.IUserService;



@Controller
@RequestMapping("/system/penalty")
public class PenaltyController extends BaseController{
	
	private String prefix = "system/penalty";
	@Autowired
	private PenaltyService penaltyService;
	
	@Autowired
	private IDeptService deptService;
	
	@Autowired
	private RosterService rosterService;
	
	@Autowired
	private IUserService userService;
	@RequiresPermissions("payroll:performance:view")
	@RequestMapping()
	public String goods(ModelMap mmap) {
		User user  = ShiroUtils.getSysUser();
		User user1 = userService.selectUserById(user.getUserId());
		mmap.put("user", user1);
		return prefix + "/penalty";
	}
	@RequiresPermissions("payroll:penalty:list")
	@PostMapping("/list") 
	@ResponseBody
	public TableDataInfo list(Penalty penalty) {
		startPage();
		List<Penalty> selectPenalty = penaltyService.selectPenalty(penalty);
		return getDataTable(selectPenalty);
	}
	@RequiresPermissions("payroll:penalty:add")
	@Log(title = "参数管理", businessType = BusinessType.INSERT)
	@PostMapping("/showAdd") 
	@ResponseBody
	public Map<String, Object> add(Penalty penalty) {
		Map<String, Object> result = new HashMap<>();
		try {
			penaltyService.addPenalty(penalty);
			result.put("status", "0");
		}catch (Exception e) {
			// TODO: handle exception
			result.put("status", "500");
			result.put("msg", e);
		}
		return result;
	}
	
	@RequiresPermissions("payroll:penalty:delete")
	@Log(title = "参数管理", businessType = BusinessType.DELETE)
	@RequestMapping("/delete")
	@ResponseBody
	public Map<String,String> delete(@RequestParam("ids[]")int[] ids) {
		Map<String, String> result = new HashMap<String,String>();
		penaltyService.deletePenalty(ids);
		result.put("msg", "删除成功");
		return result;
	}
	@RequestMapping("/getPenalty")
	@ResponseBody
	public Map<String,Object> getPenalty(int id) {
		System.out.println(id);
		Map<String,Object> result = new HashMap<String,Object>();
		Penalty penalty = penaltyService.getPenalty(id);
		System.out.println(penalty.toString());
		result.put("penalty", penalty);
		return result;
	}
	@RequestMapping("/getdeptss")
	@ResponseBody
	public Map<String,Object> getdept() {
		Map<String,Object> result = new HashMap<String,Object>();
		List<Dept> dList = deptService.selectDeptListes();
		result.put("dList", dList);
		return result;
	}
	@RequiresPermissions("payroll:penalty:update")
	@Log(title = "参数管理", businessType = BusinessType.UPDATE)
	@RequestMapping("/eidtPenalty")
	@ResponseBody
	public Map<String, Object> upadtePenalty(Penalty penalty) {
		Map<String, Object> result = new HashMap<>();
		try {
			long i = penaltyService.updatePenalty(penalty);
			result.put("status","0" );
			System.out.println(i);
		}catch (Exception e) {
			// TODO: handle exception
			result.put("status", "500");
			result.put("msg", e);
		}
		return result;
	}
	
}
